/**
 * @function 销售数据分析
 * @param client  openai client
 * @param {csv} data
 * @param {String} query 问题
 * @returns 数据分析的结果
 * @author wbk 2024-6-21
 */

export const getSaleReport = async (client, data, query) => {
  const messages = [
    {
      role: 'system',
      content: 'You are a professional data analyst.',
    },
    {
      role: 'user',
      content: `
        Here is the sale data: \n ${data} \n \n
        Please generate a report to answer
        the following question: \n
        ${query}
      `,
    },
  ];

  let response = await client.chat.completions.create({
    model: 'gpt-3.5-turbo',
    messages,
    temperature: 0,
    n: 1,
    max_tokens: 1000,
  });

  return response.choices[0].message.content;
};

/**
 * @function 多数相和
 * @param  {...any} args
 * @returns 多数之和
 */
export const add = (...args) => args.reduce((acc, item) => acc + item, 0);
